/*
    SDL - Simple DirectMedia Layer
    Partial implementation of SDL library (originally written by
    Sam Lantinga <slouken@libsdl.org>) for the particular purpose to support
    Prequengine (http://code.google.com/p/prequengine/) on BlackBerry(tm)
    tablets and smartphones.

    Copyright (C) 2013  xlamsp

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

    xlamsp@gmail.com
*/

#ifndef SDL_SYSVIDEO_H_
#define SDL_SYSVIDEO_H_

#include "SDL_config.h"
#include "SDL_video.h"


/* Define the SDL video driver structure */
#define _THIS struct SDL_VideoDevice *_this
struct SDL_VideoDevice {
    /* * * */
    /* The name of this video driver */
    const char *name;

    /* * * */
    /* Initialization/Query functions */

    /* Initialize the native video subsystem, filling 'vformat' with the
       "best" display pixel format, returning 0 or -1 if there's an error.
     */
    int (*VideoInit)(_THIS, SDL_PixelFormat *vformat);

    /* Set the requested video mode, returning a surface which will be
       set to the SDL_VideoSurface.  The width and height will already
       be verified by ListModes(), and the video subsystem is free to
       set the mode to a supported bit depth different from the one
       specified -- the desired bpp will be emulated with a shadow
       surface if necessary.  If a new mode is returned, this function
       should take care of cleaning up the current mode.
     */
    SDL_Surface *(*SetVideoMode)(_THIS, SDL_Surface *current,
                int width, int height, int bpp, Uint32 flags);

    /* Sets the color entries { firstcolor .. (firstcolor+ncolors-1) }
       of the physical palette to those in 'colors'. If the device is
       using a software palette (SDL_HWPALETTE not set), then the
       changes are reflected in the logical palette of the screen
       as well.
       The return value is 1 if all entries could be set properly
       or 0 otherwise.
    */
//    int (*SetColors)(_THIS, int firstcolor, int ncolors,
//                SDL_Color *colors);

    /* This pointer should exist in the native video subsystem and should
       point to an appropriate update function for the current video mode
     */
    void (*UpdateRects)(_THIS, int numrects, SDL_Rect *rects);

    /* Reverse the effects VideoInit() -- called if VideoInit() fails
       or if the application is shutting down the video subsystem.
    */
    void (*VideoQuit)(_THIS);

    /* * * */
    /* Hardware acceleration functions */

    /* Information about the video hardware */
    SDL_VideoInfo info;

    /* The pixel format used when SDL_CreateRGBSurface creates SDL_HWSURFACEs with alpha */
    SDL_PixelFormat* displayformatalphapixel;

    /* Allocates a surface in video memory */
    int (*AllocHWSurface)(_THIS, SDL_Surface *surface);

    /* Perform HW accelerated blit */
    int (*BlitHWSurface)(_THIS, SDL_Surface * src, SDL_Rect * srcrect,
                SDL_Surface * dst, SDL_Rect * dstrect);

    /* Frees a previously allocated video surface */
    void (*FreeHWSurface)(_THIS, SDL_Surface *surface);

    /* Handle any queued OS events */
    void (*PumpEvents)(_THIS);

    /* * * */
    /* Data common to all drivers */
    SDL_Surface *screen;

    /* * * */
    /* Data private to this driver */
    struct SDL_PrivateVideoData *hidden;

    /* * * */
    /* The function used to dispose of this structure */
    void (*free)(_THIS);
};
#undef _THIS

typedef struct SDL_VideoDevice SDL_VideoDevice;

typedef struct VideoBootStrap {
    const char *name;
    const char *desc;
    int (*available)(void);
    SDL_VideoDevice *(*create)(int devindex);
} VideoBootStrap;

extern VideoBootStrap BB_bootstrap;

/* This is the current video device */
extern SDL_VideoDevice *current_video;

#define SDL_VideoSurface    (current_video->screen)


#endif /* SDL_SYSVIDEO_H_ */

